<%@ page contentType="text/html; charset=UTF-8" import="com.pub.database.*,java.sql.*,java.util.*"%>
<%
String lstrTableName = "flow_code";

QueryBean qbnDAO = null;

Statement stmtTableCol = null;
//Statement stmtTablePK = null;

ResultSet rsTableCol = null;
//ResultSet rsTablePK = null;

ResultSetMetaData rsmdTableCol = null;
//ResultSetMetaData rsmdTablePK = null;

StringBuffer stbTableCol = new StringBuffer();
StringBuffer stbTablePK = new StringBuffer();

try{
  qbnDAO = new QueryBean("PIS1_SWD",false,"big5","big5");

  stmtTableCol = qbnDAO.getConnection().createStatement();

  rsTableCol = stmtTableCol.executeQuery("select * from " + lstrTableName + " where rownum<=1");
  //rsTablePK = qbnDAO.getConnection().getMetaData().getPrimaryKeys(null,null,lstrTableName);

  rsmdTableCol = rsTableCol.getMetaData();

  stbTableCol=stbTableCol.append("<table border='1' cellspacing='0' cellpadding='0'>");

  /*stbTableCol.append("<th>");

  for(int i=1;i<=rsTableCol.getMetaData().getColumnCount();i++){
    stbTableCol.append("<td>");
    stbTableCol.append(rsTableCol.getMetaData().getColumnName(i));
    stbTableCol.append("</td>");
  }

  stbTableCol.append("</th>");*/
  stbTableCol.append("<tr>");

  while(rsTableCol.next()){
    System.out.println(stbTableCol.append(rsTableCol.getString("COLUMN_NAME")));
    /*for(int i=0;i<=rsTableCol.getMetaData().getColumnCount();i++){
      stbTableCol.append("<td>");
      stbTableCol.append(rsTableCol.getString(i));
      stbTableCol.append("</td>");
    }*/
  }

  stbTableCol.append("</tr></table>");
}
catch(Exception e){
  e.printStackTrace();
}
finally{
  /*if(rsTablePK!=null){
    try{rsTablePK.close();rsTablePK = null;}catch(Exception e){e.printStackTrace();}
  }
  if(stmtTablePK!=null){
    try{stmtTablePK.close();}catch(Exception e){e.printStackTrace();}
  }
  if(rsmdTablePK != null){
    rsmdTablePK = null;
  }*/
  if(rsmdTableCol != null){
    rsmdTableCol = null;
  }
  if(rsTableCol!=null){
    try{rsTableCol.close();rsTableCol = null;}catch(Exception e){e.printStackTrace();}
  }
  if(stmtTableCol!=null){
    try{stmtTableCol.close();}catch(Exception e){e.printStackTrace();}
  }
  if(qbnDAO!=null){
    try{qbnDAO.close();qbnDAO=null;}catch(Exception e){e.printStackTrace();}
  }
}
%>
<html>
<head>
<title>
testGetTableSchema
</title>
</head>
<body bgcolor="#ffffff">
<p>
  <%=stbTableCol.toString() %>
</p>
</body>
</html>
